package tjx.Action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import tjx.struts.beans.User;

import java.util.Date;

public class FormtextAction extends ActionSupport{
    private User user;
    private String username;
    private String password;
    private String realname;
    private Integer age;
    private Date birthday;
    private String tip;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRealname() {
        return realname;
    }

    public void setRealname(String realname) {
        this.realname = realname;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getTip() {
        return tip;
    }

    public void setTip(String tip) {
        this.tip = tip;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String regist() throws Exception
    {
        ActionContext actionContext=ActionContext.getContext();
        Integer counter=(Integer)actionContext.getApplication().get("counter");
        if(counter==null)
        {
            counter=1;
        }
        else
        {
            counter=counter+1;
        }
        actionContext.getApplication().put("counter",counter);
        actionContext.getSession().put("username",getUsername());
        actionContext.getSession().put("password",getPassword());
        actionContext.getSession().put("realname",getRealname());
        actionContext.getSession().put("age",getAge());
        System.out.println("username="+username);
        System.out.println("password="+password);
        System.out.println("realname="+realname);
        System.out.println("age="+age);
//        ActionContext.getContext().getSession().put("username",getUsername());
//        setTip("HAPPY,"+getUsername()+",YOU ARE GREAT SUCCESS");
        return SUCCESS;
    }
    @Override
    public String execute() throws Exception {
        if (getUsername().equals("crazy.org")&&getPassword().equals("leegang"))
        {
            ActionContext.getContext().getSession().put("username",getUsername());
            setTip("HELLO,"+getUsername()+",Login SUCCESS");
            return SUCCESS;
        }
        return ERROR;
    }
}
